	/*
 * CryptoFs.cpp
 *
 *  Created on: Mar 22, 2010
 *      Author: Lukasz Spintzyk
 */
#include "ph.h"

#include "fusecpp.h"
#include "CommandLineParsers.h"
#include "OtherFsOperations.h"

#include "Filesystem.h"
#include "DirectoryReader.h"



struct fuse_args_mock
{
	char _chr_file[100];
	char _chr_key[100];
	char _chr_iv[100];
	char _space[200];
};

static struct fuse_opt CryptoOpts[] =
{
		{"--device %s", offsetof(fuse_args_mock,_chr_file), 100},
		{"--key %s", offsetof(fuse_args_mock,_chr_key), 100},
		{"--IV %s", offsetof(fuse_args_mock,_chr_iv), 100}
};




int main(int argc, char* argv[])
{
	// -device ./tst.fs --key AA::22::33::44::55::66::77::88::01::22::33::44::55::66::77::88
	int ret = 0;
	struct FilesystemMountArgs
		 mount_args = parseMountArgs(argc, argv);

	struct fuse_args args = FUSE_ARGS_INIT(0, NULL);

	struct fuse_args_mock mockup;
	memset(&mockup, 0, sizeof(struct fuse_args_mock));


	if (mount_args.exit)
	{
		return 0;
	}

	if (argc >= 2)
	{
		fuse_opt_add_arg(&args, argv[0]);
		fuse_opt_add_arg(&args, argv[1]);
	}

	for (int i = 0; i < argc; ++i)
	{
		if (strcmp(argv[i], "-d") == 0)
		{
			fuse_opt_add_arg(&args, argv[i]);
		}
		else if (strcmp(argv[i], "-s") == 0)
		{
			fuse_opt_add_arg(&args, argv[i]);
		}
	}

	fuse_cpp::FuseDispatcher& fuseDis = CudaCryptoFs::initDispatcher();
	ret =  fuse_main(args.argc, args.argv, fuseDis.get_fuseOps(), (void*)&mount_args);
	fuse_opt_free_args(&args);

	return ret;
}
